// 从localStorage中获取当天的投票结果
function getVotes() {
	let today = new Date().toISOString().slice(0, 10);
	let votes = localStorage.getItem(today);
	if (votes) {
		return JSON.parse(votes);
	} else {
		return {};
	}
}

// 更新当天的投票结果到localStorage
function updateVotes(votes) {
	let today = new Date().toISOString().slice(0, 10);
	localStorage.setItem(today, JSON.stringify(votes));
}

// 显示当天的投票结果
function showVotes() {
	let votes = getVotes();
	let resultDiv = document.getElementById("result");
	resultDiv.innerHTML = "";
	for (let key in votes) {
		let progress = votes[key].progress;
		let coolness = votes[key].coolness;
		resultDiv.innerHTML += "<p>匿名用户：" + key + " 投票结果：工作进展" + progress + " 装酷程度" + coolness + "</p >";
	}
}

// 提交表单，更新投票结果
function submitForm() {
	let progress = document.querySelector('input[name="progress"]:checked');
	let coolness = document.querySelector('input[name="coolness"]:checked');
	if (progress && coolness) {
		let votes = getVotes();
		let key = Math.random().toString(36).substr(2, 10); // 生成一个随机的key作为匿名用户标识
		votes[key] = {
			progress: progress.value,
			coolness: coolness.value
		};
		updateVotes(votes);
		showVotes();
		alert("提交成功！");
	} else {
		alert("请完成所有投票选项！");
	}
}

// 页面加载完成后，显示当天的投票结果
window.onload = function() {
	showVotes();
}
